#include <cstdio>

#include "Game.h"
#include "Renderer.h"

Game::Game() : state( GAME_MENU ) {
  initializeSDL();
  gameRenderer = new Renderer();
}

Game::~Game() {
  delete gameRenderer;
  shutdownSDL();
}

void Game::setState( GameState_t newState ) { state = newState; }
GameState_t Game::getState() const { return state; }

void Game::initializeSDL() {
  if( SDL_Init( SDL_INIT_AUDIO | SDL_INIT_VIDEO ) != 0 ) {
    fprintf( stderr, "Failed to initialize SDL!" );
    state = GAME_EXITED; // Wylaczamy gre - bez SDLa to ona sie nie obejdzie.
    return;
  }
  SDL_WM_SetCaption( "Ataraxia RPG", NULL );
}

void Game::shutdownSDL() {
  SDL_Quit();
}

void Game::mainLoop() {
  while( SDL_PollEvent( &eventHandler ) ) {
    switch( eventHandler.type ) {
      case SDL_QUIT:
        state = GAME_EXITED;
        return;
      break;
    }
    handleEvents();
  }
  gameRenderer->refreshScreen();
}

void Game::handleEvents() {
  switch( state ) {
    default: return; break;

    case GAME_MENU:
      // ...
    break;

    case GAME_GAME:
      // ...
    break;

    case GAME_PAUSED:
      // ...
    break;
  }
}
